with Ada.Strings.Bounded;
with Ada.Text_IO;
with Ada.Sequential_IO;

use Ada;

with App_Configuration; use App_Configuration;

--
-- read a text file into a String
--

generic

   Max_Stack_Size : Positive;

   Max_Heap_Size  : Positive;

package Text_File_Reader is

   --
   -- file object for small files - using Text IO package
   --

   Small_File_In : Text_IO.File_Type;

   --
   -- character buffer for reading small files
   --

   Char_In : Character;

   --
   -- exceptions
   --

   File_Empty : exception;

   --
   -- argument types
   --

   FILE_NAME_AND_PATH_MAX_LEN : constant := 400;

   subtype File_Name_Type is String

      with Dynamic_Predicate => File_Name_Type'Size

            <= FILE_NAME_AND_PATH_MAX_LEN;

   --
   -- return type
   --
   --    for smaller files, where String returned from function
   --

   subtype Small_Output_String_Type is String

         with Dynamic_Predicate =>

            Small_Output_String_Type'Size <= Max_Stack_Size ;

   package Small_File_Contents_String_Type is new Strings.Bounded

         .Generic_Bounded_Length( Max_Stack_Size );

   Small_File_Contents : Small_File_Contents_String_Type.Bounded_String;


   --
   -- output type
   --
   --    for larger files, procedure approach modifying bounded string at
   --    package Level
   --

   package Large_File_Contents_String_Type is new Strings.Bounded

         .Generic_Bounded_Length( Max_Heap_Size );

   Large_File_Contents : Large_File_Contents_String_Type.Bounded_String;

   subtype Large_File_Buffer_Type is String (1 .. BUFFER_LIMIT);

   Large_File_Buffer : Large_File_Buffer_Type;

   package Large_File_IO is new Sequential_IO( Large_File_Buffer_Type );

   --
   -- large file in file type - using sequential IO package
   --

   Large_File_In : Large_File_IO.File_Type;


   --
   -- read a text file into a String
   --
   --    for smaller files not exceeding stack space limits
   --

   function Read_Into_String( File_Name : in File_Name_Type )

         return Small_Output_String_Type;

   function Read_Into_String( File_Name : in File_Name_Type;

                              Resume : in out Boolean )

         return Small_Output_String_Type;


   --
   -- read a text file into a String
   --
   --    output in 'File_Contents' bounded string
   --
   --    for larger files needing heap space
   --

   procedure Read_Into_String( File_Name : in File_Name_Type );


end Text_File_Reader;